package core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Wijnand
 */
public class DispatcherPort implements Port, Serializable {

    List<TriggerPort> targets = new ArrayList<TriggerPort>();

    public void callTargets() {
        for (TriggerPort target : targets) {
            Tracker.getInstance().startDispatch(this, target);
            target.call();
            Tracker.getInstance().stopDispatch(this);
        }

    }

    public void addTarget(TriggerPort t) {
        this.targets.add(t);
    }

    public void removeTarget(TriggerPort t) {
        this.targets.remove(t);
    }

    public void clearTargets() {
        this.targets.clear();
    }

    public boolean hasTarget(TriggerPort target) {
        return this.targets.contains(target);
    }

    public List<TriggerPort> getTargetList() {
        return this.targets;
    }
}
